package com.kmproject.haifu.mvp.presenter;

import android.app.Application;

import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.RxUtils;
import com.kmproject.haifu.mvp.contract.HousePublishMainContract;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseMainBean;
import com.kmproject.haifu.mvp.model.entity.beans.PublishNumCheakBean;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 06/25/2019 15:54
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class HousePublishMainPresenter extends BasePresenter<HousePublishMainContract.Model, HousePublishMainContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    public HousePublishMainPresenter(HousePublishMainContract.Model model, HousePublishMainContract.View rootView) {
        super(model, rootView);
    }

    /**
     * 校验是否可以发布
     */
     public void isPublishCount(){
        mModel.isPublishCount().compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean<PublishNumCheakBean>>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean<PublishNumCheakBean> publishNumCheakBeanResultBean) {
                      if (AppUtil.isSuccess(publishNumCheakBeanResultBean))
                      {
                          mRootView.isPublishCountSuccess(publishNumCheakBeanResultBean.getData());
                      }else {
                          mRootView.showMessage(publishNumCheakBeanResultBean.getMessage());
                      }
                    }
                });
     }

    /**
     * 初始化数据
     * @return
     */
    public  List<HouseMainBean> getDatas(){
        List<HouseMainBean> houseMainBeans=new ArrayList<>();
         List<HouseMainBean.HouseMainItem> houseMainItems1=new ArrayList<>();
        houseMainItems1.add(new HouseMainBean.HouseMainItem("zf","租房", R.drawable.house_main_zf_new_icon));
//        houseMainItems1.add(new HouseMainBean.HouseMainItem("sf","售房", R.drawable.house_main_mf_new_icon));
        houseMainItems1.add(new HouseMainBean.HouseMainItem("qz","求租", R.drawable.house_main_qz_icon));
        houseMainItems1.add(new HouseMainBean.HouseMainItem("eswp","二手物品", R.drawable.house_main_mxz_icon));
//        houseMainItems1.add(new HouseMainBean.HouseMainItem("tcfw","同城服务", R.drawable.house_main_tgfw_icon));

        HouseMainBean houseMainBean1=new HouseMainBean("",houseMainItems1);

//        List<HouseMainBean.HouseMainItem> houseMainItems2=new ArrayList<>();
//        houseMainItems2.add(new HouseMainBean.HouseMainItem("mxz","卖闲置", R.drawable.house_main_mxz_icon));
//        houseMainItems2.add(new HouseMainBean.HouseMainItem("qg","求购", R.drawable.house_main_qg_icon));
//        houseMainItems2.add(new HouseMainBean.HouseMainItem("hs","回收", R.drawable.house_main_sg_icon));
//        HouseMainBean houseMainBean2=new HouseMainBean("二手市场",houseMainItems2);

//        List<HouseMainBean.HouseMainItem> houseMainItems3=new ArrayList<>();
//        houseMainItems3.add(new HouseMainBean.HouseMainItem("tgfw","提供服务", R.drawable.house_main_tgfw_icon));
//        HouseMainBean houseMainBean3=new HouseMainBean("二手市场",houseMainItems3);
        houseMainBeans.add(houseMainBean1);
//        houseMainBeans.add(houseMainBean2);
//        houseMainBeans.add(houseMainBean3);
        return houseMainBeans;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }
}
